<template>
  <div>
    <el-form :model="activityInfo" :rules="rules" ref="activityInfo" label-width="100px" class="demo-ruleForm">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="activityInfo.name"></el-input>
      </el-form-item>
      <el-col :span="12">
        <el-form-item label="性别" prop="gender">
          <el-radio-group v-model="activityInfo.gender" :disabled="isContent">
            <el-radio :label="0">男</el-radio>
            <el-radio :label="1">女</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-col>
      <el-col :span="11">
        <el-form-item label="手机号" prop="phone" v-model="activityInfo.phone">
          <el-input v-model.number="activityInfo.phone" autocomplete="off" :disabled="isContent"></el-input>
        </el-form-item>
      </el-col>
      <el-form-item label="所属院系" required>
        <el-col :span="11">
          <el-form-item prop="collegeId">
            <el-select filterable v-model="activityInfo.collegeId" placeholder="请选择学院"
              @change="colleageChanged(userInfo.collegeId)" :disabled="isContent">
              <el-option v-for="(item, index) in collegeAndMajor" :key="index" :label="item.collegeName"
                :value="item.collegeId"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="line" :span="2" style="text-align: center">-</el-col>
        <el-col :span="11">
          <el-form-item prop="majorId">
            <el-select v-model="activityInfo.majorId" placeholder="请选择专业" :disabled="isContent">
              <el-option filterable v-for="(item, index) in majorList" :key="index" :label="item.name"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即报名</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      collegeAndMajor: '',
      majorList:[],
      activityInfo: {
        name: '',
        gender: '',
        phone: '',
        majorId: "",
        collegeId: "",
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入姓名",
            trigger: "blur",
          },
          {
            min: 2,
            max: 5,
            message: "长度在 2 到 5 个字符",
            trigger: "blur",
          },
        ],
        collegeId: [
          {
            required: true,
            message: "请选择学院",
            trigger: "blur",
          },
        ],
        majorId: [
          {
            required: true,
            message: "请选择专业",
            trigger: "blur",
          },
        ],
        phone: [
          {
            required: true,
            message: "请输入手机号",
            trigger: "blur",
          },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: "手机号码格式不正确",
          },
        ],
        gender: [
          {
            required: true,
            message: "请选择性别",
            trigger: "blur",
          },
        ]
      }
    };
  },
  methods: {
    getColInfo(){
    this.$store.dispatch('queryCollege').then(() => {
      this.collegeAndMajor = this.$store.state.collegeAndMajor;
  console.log(this.$store.state.collegeAndMajor); // 这里应该能获取到数据
}).catch((error) => {
  console.error('获取学院专业列表失败', error);
});
   },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>
